package com.hxd.otc.module.my.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.common.enums.ExValidType;
import com.hxd.otc.module.my.bean.ImageCodeBean;
import com.hxd.otc.module.my.bean.UserStatusBean;
import com.hxd.otc.module.my.contract.SecurityCenterContract;
import com.hxd.otc.module.my.model.UserModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.utils.EncryptUtils;

/**
 * Created by lzy on 2018/6/12 0012.
 * description ${安全中心}
 */
public class SecurityCenterPresenter extends BasePresenter<SecurityCenterContract.View> implements SecurityCenterContract.Presenter {

    private final UserModel mUserModel;

    public SecurityCenterPresenter(SecurityCenterContract.View view) {
        super(view);
        mUserModel = UserModel.getInstance();
    }

    @Override
    public void findCardStatus() {
        mUserModel.findCardStatus(new BaseObserver<UserStatusBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull UserStatusBean userStatusBean) {
                mView.findCardStatusSuccess(userStatusBean);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.findCardStatusFail(errMessage);
            }
        }, mView.<BaseBean<UserStatusBean>>bindAutoDispose());
    }

    @Override
    public void onSetExValidType(final ExValidType exValidType) {
        mUserModel.setValidType(exValidType.getValidType(), new BaseObserver<ImageCodeBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ImageCodeBean imageCodeBean) {
                mView.setValidTypeSuccess(exValidType);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ImageCodeBean>>bindAutoDispose());
    }

    @Override
    public void changeExValidType(final ExValidType newExValidType, String verCode) {

        mUserModel.changeExValidType(newExValidType.getValidType(), verCode, new BaseObserver<ImageCodeBean>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ImageCodeBean imageCodeBean) {
                mView.setValidTypeSuccess(newExValidType);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ImageCodeBean>>bindAutoDispose());
    }

    @Override
    public void sendSetVerifyModeSms(final ExValidType newExValidType) {
        mUserModel.sendExValidTypeMobileSms("exchange_pass", new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.getVerifyModeSmsSuccess(newExValidType);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

    @Override
    public void sendExValidTypeEmail(final ExValidType newExValidType) {
        mUserModel.sendExValidTypeEmail("exchange_pass", new BaseObserver<String>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull String s) {
                mView.getVerifyModeEmailSuccess(newExValidType);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<String>>bindAutoDispose());
    }

}
